package com.lanswon.qzsmk.controller.appManageController;

import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ctc.wstx.util.StringUtil;
import com.lanswon.qzsmk.base.CardContants;
import com.lanswon.qzsmk.business.EPLoadBusiness;
import com.lanswon.qzsmk.controller.cardManageController.BaseController;
import com.lanswon.qzsmk.service.appManageService.BalanceTransfService;
import com.lanswon.qzsmk.vo.BalanceTransfVo;
import com.lanswon.qzsmk.vo.RechargeCancelVo;
import com.lanswon.smk.common.kmsserror.KmssException;

/**
 * 余额转移Controller
 * @author guyw
 *
 */
@Controller
@RequestMapping(value="/balanceTransfer")
public class BalanceTransferController  {
	
	@Autowired
	BalanceTransfService bts;
	
	@Autowired
	EPLoadBusiness ep;
	
	/**
	 * 链接余额转移页面
	 * @return
	 */
	@RequiresPermissions("balanceTransfer:index")
	@RequestMapping(value="index",name="余额转移页面,balanceTransfer:index",method={RequestMethod.POST,RequestMethod.GET})
	public String goBalanceTransfer(){
		return "BalanceTransfer";
	}
	
	/**
	 * 获取余额转移信息
	 * @param citizenCardNo
	 * @param isRead
	 * @return
	 */
	@RequiresPermissions("balanceTransfer:getBalanceTransferInfo")
	@RequestMapping(value="/getBalanceTransferInfo",name="获取余额转移信息,balanceTransfer:getBalanceTransferInfo",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object>getBalanceTransferInfo(BalanceTransfVo btv){
		System.out.println(btv.toString());
		Map<String, Object> map=new HashMap<>();
		BalanceTransfVo bVo=null;
		if(btv.getIsRead().equals(CardContants.CARD_NO_READ)){
			bVo=bts.showBaseInfo_no(btv);
			map.put("bvo_no", bVo);
		}else if(btv.getIsRead().equals(CardContants.CARD_IS_READ)){
			if (btv.getNewCitizenCardNo()!=null&&btv.getOldCitizenCardNo()==null) {
				bVo=bts.showBaseInfo_is_new(btv);
				map.put("bvo_is_new", bVo);
			}else if(btv.getOldCitizenCardNo()!=null&&btv.getNewCitizenCardNo()==null){
				bVo=bts.showBaseInfo_is_old(btv);
				map.put("bvo_is_old", bVo);
			}
		}
		return map;
	}
	
	/**
	 * 检测2张卡是否匹配
	 * @param btv
	 * @return
	 */
	@RequiresPermissions("balanceTransfer:getBalanceTransferInfo")
	@ResponseBody
	@RequestMapping(value="/checkCardsIsconsistent",name="检测卡是否匹配,balanceTransfer:getBalanceTransferInfo",method=RequestMethod.POST)
	public Map<String, Object>checkCardsIsconsistent(BalanceTransfVo btv){
		System.out.println(btv.toString());
		Map<String, Object> map=new HashMap<>();
		//是否是新卡
		boolean check_1=bts.checkCard_1(btv.getNewCitizenCardNo());
		//是否匹配
		if(btv.getOldCitizenCardNo()!=null){
			System.out.println(btv.getOldCitizenCardNo());
			boolean check_2=bts.checkCard_2(btv.getNewCitizenCardNo(),btv.getOldCitizenCardNo());
			map.put("check_2", check_2);
		}
		
		map.put("check_1", check_1);
		
		return map;
	}
	
	@RequiresPermissions("balanceTransfer:updateblanceForOldCard")
	@ResponseBody
	@RequestMapping(value="/updateblanceForOldCard",name="旧卡不可读消费,balanceTransfer:updateblanceForOldCard",method=RequestMethod.POST)
	public Map<String, Object>updateblanceForOldCard(RechargeCancelVo rv) throws Exception, KmssException{
		Map<String, Object> map=null;
		System.out.println(rv.getCitizenCardNo());
		map=ep.checkTacByRechargeCancel(rv);
		return map;
	}
}
